package com.wap.framework.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter {

	private String encoding = null;
	private FilterConfig filterConfig = null;	
	
	public void destroy() {
		this.encoding = null;
		this.filterConfig = null;
	}

	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain filterChain) throws IOException, ServletException {
		if(encoding != null) {
			req.setCharacterEncoding(encoding);
		}

		filterChain.doFilter(req, resp);
	}

	public void init(FilterConfig config) throws ServletException {
		this.filterConfig = config;
		this.encoding = this.filterConfig.getInitParameter("encoding");
	}
}
